version 9.2#delimit;set more off;set mem 500m;clear;  quietly log;  local logon = r(status);  if "`logon'" == "on" {; log close; };log using smb2010isq-analyze, text replace; /*	************************************************************	*//*     	File Name:	smb2010isq-analyze.do				*//*     	Date:   	July 12, 2011 					*//*      Author: 	Dan Morey and Frederick J. Boehmke		*//*      Purpose:	This file replicates the regression results in 	*//*			Tables 1 and 2 for the duration with selection 	*//*			models of conflict onset and duration. 		*//*      Input File: 	smb2010isq.dta					*//*      Output File:	smb2010isq-analyze.log				*//* 	Requires:	dursel.ado					*//*	Version:	Stata 9.2 or above.				*//*	************************************************************	*/	/****************************************************************/	/* This program combines the results from the imputed data 	*/	/* sets. The model is run once on each data set and the  	*/	/* resulting coefficient vectors and covariance matrices are 	*/	/* saved to combine according to the formula. -micombine- won't	*/	/* work since we're using a user-written MLE.			*/	/****************************************************************/capture program drop midisp;program define midisp;	local names: colnames(Q1);	matrix Q = (Q1 + Q2 + Q3 + Q4 + Q5)/5;		/* MI parameter vectors.*/	matrix W = (W1 + W2 + W3 + W4 + W5)/5;		/* MI covariances.     	*/	local  k = colsof(Q);				/* Number of parameters.*/	forvalues i=1/5 {;	  matrix QQ=Q`i'-Q;	  if `i'==1 {;		matrix B=(QQ)'*QQ;		};	  else matrix B = B + (QQ)'*QQ;	};	matrix B=B/(5-1);				/* Covariance adjustment with 5 imputations. */	matrix V=W+(1+1/5)*B;				/* Final covariance.   	*/	ereturn post Q V;				/* Display the results. */	ereturn display, plus neq(2);        _diparm Z_alpha, prob label("Z_alpha");	_diparm Z_alpha, prob label("rho") function(((exp(2*(@))-1)/(exp(2*(@))+1))/4)		derivative((4*exp(2*@)/(exp(2*@)+1)^2)/4);		        di in smcl in gr "{hline 13}{c BT}{hline 64}";	_diparm ln_p, level(`level') prob label("ln_p");	_diparm ln_p, level(`level') prob label("p") function(exp(@)) derivative(exp(@));		        di in smcl in gr "{hline 78}";end;
	/****************************************************************/	/* Read in the data and estimate the models for Table 1.  	*/	/****************************************************************/		/* Make sure to chnge this line if you run the 		*/		/* imputation to reflect the new filename you created.	*/	
use smb2010isq.dta, clear;
		/* Table 1, Model 1:  Naive Model. No imputation.	*/		/* imputeid ==1 restricts to one of the imputed data	*/		/* sets and sample==1 restricts to observations that	*/		/* were complete before imputations. 			*/		
streg COWIO jdemo2 totactor majdyad hihost pratio distance strtyr if imputeid==1 & sample==1, 	dist(weibull) nohr cluster(dyadid);

		/* Table 1, Model 2:  Duration with Selection Model.	*/		/* No imputation (same sample restriction as above). 	*/		
dursel cumdurat COWIO jdemo2 totactor majdyad hihost pratio distance strtyr 	if imputeid==1 & sample==1, select(enter = COWIO jdemo2 pratio majdyad distance 	_spline1 _spline2 _spline3  dur_peac) dist(weibull) cluster(dyadid);
		/* Table 1, Model 3:  Duration with Selection Model.	*/		/* Use imputated data sets. Run a loop over each data 	*/		/* set (indicated by imputeid) and save results, then 	*/		/* run the midisp program to combine and display the 	*/		/* results.						*/forvalues id=1/5 {;	display in yellow "Running model on dataset " `id';    	quietly dursel cumdurat COWIO jdemo2 totactor majdyad hihost pratio distance 	  strtyr if imputeid==`id', select(enter = COWIO jdemo2 pratio majdyad distance 	  dur_peac _spline1 _spline2 _spline3) dist(weibull) cluster(dyadid);  	matrix Q`id' = e(b);  	matrix W`id' = e(V);	local  ll`id' = e(ll);	  	};	midisp;	di "Average log-likelihood: " (`ll1' + `ll2' + `ll3' + `ll4' + `ll5')/5;  	/************************************************/	/* Now estimate the models for Table 2.  	*/	/************************************************/		/* Table 2, Model 1:  Duration with Selection Model.	*/		/* Use imputated data sets. Dependent variable is 	*/		/* fatal MIDS rather than all MIDS.			*/forvalues id=1/5 {;	display in yellow "Running model on dataset " `id';  	quietly dursel cumdurat_fat COWIO jdemo2 totactor majdyad hihost pratio distance 	  strtyr if imputeid==`id', select(enter_fat = COWIO jdemo2 pratio majdyad distance 	  dur_peac _spline1 _spline2 _spline3) dist(weibull) cluster(dyadid);  	matrix Q`id' = e(b);  	matrix W`id' = e(V);	local  ll`id' = e(ll);	  	};	midisp;	di "Average log-likelihood: " (`ll1' + `ll2' + `ll3' + `ll4' + `ll5')/5;		/* Table 2, Model 2:  Duration with Selection Model.	*/		/* Use imputated data sets. IO variables is commitment-	*/		/* enhancing IOS.					*/forvalues id=1/5 {;	display in yellow "Running model on dataset " `id';  	quietly dursel cumdurat IntrvIOs jdemo2 totactor majdyad hihost pratio distance 	  strtyr if imputeid==`id', select(enter = IntrvIOs jdemo2 pratio majdyad distance 	  dur_peac _spline1 _spline2 _spline3) dist(weibull) cluster(dyadid);  	matrix Q`id' = e(b);  	matrix W`id' = e(V);	local  ll`id' = e(ll);	  	};	midisp;	di "Average log-likelihood: " (`ll1' + `ll2' + `ll3' + `ll4' + `ll5')/5;		/* Table 2, Model 2:  Duration with Selection Model.	*/		/* Use imputated data sets. IO variables is 		*/		/* information-providing IOS.				*/forvalues id=1/5 {;	display in yellow "Running model on dataset " `id';  	quietly dursel cumdurat sIGOist3 jdemo2 totactor majdyad hihost pratio distance 	  strtyr if imputeid==`id', select(enter = sIGOist3 jdemo2 pratio majdyad distance 	  dur_peac _spline1 _spline2 _spline3) dist(weibull) cluster(dyadid);  	matrix Q`id' = e(b);  	matrix W`id' = e(V);	local  ll`id' = e(ll);	  	};	midisp;	di "Average log-likelihood: " (`ll1' + `ll2' + `ll3' + `ll4' + `ll5')/5;  log close;clear;exit, STATA;